package com.lagou.edu.vo;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lagou.edu.common.status.ResultStatus;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

/**
 * @author 赵虎
 * @date 2021/2/18 2:27 下午
 */
@Data
@Builder
public class ResultVO implements Serializable {
    // 定义jackson对象
    private static final ObjectMapper MAPPER = new ObjectMapper();

    // 响应业务状态
    private Integer status;

    // 响应消息
    private String msg;

    // 响应中的数据
    private Object data;


    public static ResultVO ok(Object data) {
        return ResultVO.builder().data(data).status(ResultStatus.SUCCESS.getCode()).build();
    }

    public static ResultVO ok() {
        return ResultVO.builder().status(ResultStatus.SUCCESS.getCode()).build();
    }

    public static ResultVO fail(ResultStatus resultStatus, String msg) {
        return ResultVO.builder().status(resultStatus.getCode()).msg(msg).build();
    }

}
